package shop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class DeleteProductService implements DeleteProduct{
	DBProduct  DBP;
	
	@Autowired
	public DeleteProductService(DBProduct DBP){
		this.DBP = DBP;
	}
	
	@Transactional
	public boolean deleteProduct(long ProductID){
		boolean result = false;
		try{
			if(DBP.checkProduct(ProductID)){
				DBP.deleteProduct(ProductID);
				result = true;
			}else{
				throw new ProductNotFoundException();
			}
		}catch(RuntimeException e){
			throw e;
		}
		return result;
	}
}
